package com.schoolET.result;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * @program: TianfuHealth
 * @description: 自定义分页
 * @author: Mr.Abel SJY
 * @Email thanksjava@qq.com
 * @create: 2023-07-08 16:22
 **/
@Api(tags = "分页对象")
@Data
public class MyPage<T> {

    @ApiModelProperty(value = "数据")
    private List<T> records;

    @ApiModelProperty(value = "总数")
    private long total;

    @ApiModelProperty(value = "每页总长度")
    private long size;

    @ApiModelProperty(value = "当前页数")
    private long current;

    @ApiModelProperty(value = "总页数")
    private long pages;

    @ApiModelProperty(value = "是否有上一页")
    private Boolean hasPrevious;

    @ApiModelProperty(value = "是否有下一页")
    private Boolean hasNext;

    public MyPage(Page<?> page) {
        this.records = (List<T>) page.getRecords();
        this.total = page.getTotal();
        this.size = page.getSize();
        this.current = page.getCurrent();
        this.pages = page.getPages();
        this.hasPrevious = page.hasPrevious();
        this.hasNext = page.hasNext();
    }



    public static MyPage page(Page<?> page) {
        return new MyPage(page);
    }
}
